package com.farm.controller;

import com.farm.service.AnalyseService;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/analyse")
@RestController
public class AnalyseController {

    @Autowired
    private AnalyseService analyseService;
    @GetMapping("/getYield")
    public String getYield(){
        return analyseService.getYield("http://znyj.nftec.agri.cn:8089/API/Market/GetList?token=0000000000000000&rid=25");
    }

    @GetMapping("/pricetrend")
    public String getPriceTrend(){
        return analyseService.getYield("http://znyj.nftec.agri.cn:8089/API/ProductIndex/GetList?token=0000000000000000&rid=1&sid=1");
    }


    /**
     * fishType默认330
     * @param fishType
     * @return
     */
    @GetMapping("/priceaction")
    public String getPriceAction(int fishType){
        return analyseService.getYield("http://znyj.nftec.agri.cn:8089/API/Product/GetPriceList?token=0000000000000000&pid=" + fishType + "&rid=25");
    }

    @GetMapping("/volumemovements")
    public String getVolumeMovements(){
        return analyseService.getYield("http://znyj.nftec.agri.cn:8089/API/Product/GetVolumeList?token=0000000000000000&pid=330&rid=25");
    }

    @GetMapping("/realtimeprice")
    public String getRealTimePrice(int size,int current){
        return analyseService.getYield("http://znyj.nftec.agri.cn:8089/API/Product/GetPriceNow?token=0000000000000000&rid=25&pid=-1&pageSize=" + size + "&pageNum="+ current);
    }

    @GetMapping("/realtimetransactionvolume")
    public String getRealTimeTransactionVolume(int size,int current){
        return analyseService.getYield("http://znyj.nftec.agri.cn:8089/API/Product/GetVolumeByNow?token=0000000000000000&rid=25&pid=-1&pageSize=" + size + "&pageNum="+ current);
    }

    @GetMapping("/postFreshwaterFish")
    public String postFreshwaterFish(int size,int current){
        // 构建请求参数
        List<NameValuePair> urlParameters = new ArrayList<>();
        urlParameters.add(new BasicNameValuePair("limit", String.valueOf(size)));
        urlParameters.add(new BasicNameValuePair("current", String.valueOf(current)));
        urlParameters.add(new BasicNameValuePair("pubDateStartTime", "")); // 如果没有值可以留空或者根据实际情况填写
        urlParameters.add(new BasicNameValuePair("pubDateEndTime", "")); // 如果没有值可以留空或者根据实际情况填写
        urlParameters.add(new BasicNameValuePair("prodPcatid", "1190"));
        urlParameters.add(new BasicNameValuePair("prodCatid", "1209"));
        urlParameters.add(new BasicNameValuePair("prodName", "")); // 如果没有值可以留空或者根据实际情况填写
        return analyseService.postYield("http://www.xinfadi.com.cn/getPriceData.html",urlParameters);
    }
}
